﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0065)http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html -->
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>WPF的线程模型 - this.Study(DateTime.Now) - 博客园</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META content=WPF,WPF的线程模型 name=keywords>
<META 
content=谈到多线程，很多人对其可能都不太有好感，觉得麻烦与易出错。所以我们不排除有这样的情况：假设我对“多线程”、“异步”这些字眼潜意识地有些反感，所以在编码过程中能不用就不用，觉得延迟几百毫秒还是可以忍受的，如果系统中这种“可以忍受”的地方很多，最后我们会发现系统的性能变得一团糟，界面总是在“卡”（阻塞）。这里我们讨论一下WPF的多线程模型，以便利用它使我们的UI线程得到解脱 
name=description><LINK 
href="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/common.css" type=text/css 
rel=stylesheet><LINK id=MainCss 
href="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/style.css" type=text/css 
rel=stylesheet><LINK 
href="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/common2.css" type=text/css 
rel=stylesheet><LINK 
href="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/shCore.css" type=text/css 
rel=stylesheet><LINK 
href="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/shThemeDefault.css" 
type=text/css rel=stylesheet><LINK title=RSS 
href="http://www.cnblogs.com/zhouyinhui/rss" type=application/rss+xml 
rel=alternate><LINK title=RSD href="http://www.cnblogs.com/zhouyinhui/rsd.xml" 
type=application/rsd+xml rel=EditURI>
<SCRIPT src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/jquery.js" 
type=text/javascript></SCRIPT>

<SCRIPT src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/common.js" 
type=text/javascript></SCRIPT>

<SCRIPT 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/jquery.json-1.3.min.js" 
type=text/javascript></SCRIPT>

<META content="MSHTML 6.00.2900.5897" name=GENERATOR></HEAD>
<BODY>
<FORM id=Form1 name=Form1 action=1055261.html method=post>
<DIV><INPUT id=__EVENTTARGET type=hidden name=__EVENTTARGET> <INPUT 
id=__EVENTARGUMENT type=hidden name=__EVENTARGUMENT> <INPUT 
id="&#13;&#10;__VIEWSTATE" type=hidden name=__VIEWSTATE> </DIV>
<SCRIPT type=text/javascript>
//<![CDATA[
var theForm = document.forms['Form1'];
if (!theForm) {
    theForm = document.Form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</SCRIPT>
<!--done-->
<DIV id=home>
<DIV id=header>
<DIV id=blogTitle><!--done-->
<H1><A class=headermaintitle id=Header1_HeaderTitle 
href="http://www.cnblogs.com/zhouyinhui/">this.Study(DateTime.Now)</A></H1>
<H2>专业因为专注(周银辉的开发博客)</H2></DIV><!--end: blogTitle 博客的标题和副标题 -->
<DIV id=navigator><!--done-->
<UL id=navList>
  <LI><A class=menu id=MyLinks1_HomeLink href="http://www.cnblogs.com/">博客园</A> 
  </LI>
  <LI><A class=menu id=MyLinks1_MyHomeLink 
  href="http://www.cnblogs.com/zhouyinhui/">首页</A> </LI>
  <LI><A href="http://home.cnblogs.com/">主页</A> </LI>
  <LI><A href="http://home.cnblogs.com/ing/">闪存</A> </LI>
  <LI><A class=menu id=MyLinks1_NewPostLink 
  href="http://www.cnblogs.com/zhouyinhui/admin/EditPosts.aspx?opt=1">新随笔</A> 
  </LI>
  <LI><A class=menu id=MyLinks1_ContactLink accessKey=9 
  href="http://space.cnblogs.com/msg/send/å¨é¶è¾">联系</A> </LI>
  <LI><A class=menu id=MyLinks1_Admin 
  href="http://www.cnblogs.com/zhouyinhui/admin/EditPosts.aspx">管理</A> </LI>
  <LI><A class=menu id=MyLinks1_Syndication 
  href="http://www.cnblogs.com/zhouyinhui/rss">订阅</A> <A class=aHeaderXML 
  id=MyLinks1_XMLLink href="http://www.cnblogs.com/zhouyinhui/rss"><IMG 
  style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" 
  alt=订阅 src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/rss.gif"></A> 
</LI></UL>
<DIV class=blogStats><!--done-->随笔-233&nbsp; 文章-3&nbsp; 评论-1296&nbsp; </DIV><!--end: blogStats --></DIV><!--end: navigator 博客导航栏 --></DIV><!--end: header 头部 -->
<DIV id=main>
<DIV id=mainContent>
<DIV class=forFlow><!--done-->
<DIV id=topics>
<DIV class=post>
<H1 class=postTitle><A class=postTitle2 id=ctl04_TitleUrl 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html">WPF的线程模型</A> 
</H1>
<DIV class=clear></DIV>
<DIV class=postBody>&nbsp; 
<H1><SPAN 
style="FONT-SIZE: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
WPF<SPAN style="FONT-FAMILY: 宋体">的线程模型<BR></SPAN></SPAN><SPAN 
style="FONT-FAMILY: 宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<SPAN style="FONT-SIZE: 10pt">周银辉&nbsp; </SPAN></SPAN></H1>
<P><SPAN 
style="FONT-FAMILY: 宋体">谈到多线程，很多人对其可能都不太有好感，觉得麻烦与易出错。所以我们不排除有这样的情况：假设我对“多线程”、“异步”这些字眼潜意识地有些反感，所以在编码过程中能不用就不用，觉得延迟几百毫秒还是可以忍受的，如果系统中这种“可以忍受”的地方很多，最后我们会发现系统的性能变得一团糟，界面总是在“卡”（阻塞）。这里我们讨论一下</SPAN>WPF<SPAN 
style="FONT-FAMILY: 宋体">的多线程模型，以便利用它使我们的</SPAN>UI<SPAN 
style="FONT-FAMILY: 宋体">线程得到解脱。</SPAN></P>
<P 
style="MARGIN-LEFT: 18pt; TEXT-INDENT: -18pt"><STRONG>1，</STRONG><STRONG>UI</STRONG><STRONG><SPAN 
style="FONT-FAMILY: 宋体">线程</SPAN></STRONG></P>
<P><SPAN style="FONT-FAMILY: 宋体">传说</SPAN>WPF<SPAN 
style="FONT-FAMILY: 宋体">应用程序都至少有两个线程，一个用于</SPAN>UI<SPAN 
style="FONT-FAMILY: 宋体">绘制，其隐藏于后台，另一个用于管理</SPAN>UI<SPAN 
style="FONT-FAMILY: 宋体">，包括用响应用户输入执行后台代码等。</SPAN>MSDN<SPAN 
style="FONT-FAMILY: 宋体">上对这两个线程是这样描述的：“</SPAN>Typically, WPF applications start 
with two threads: one for handling rendering and another for managing the UI. 
The rendering thread effectively runs hidden in the background while the UI 
thread receives input, handles events, paints the screen, and runs application 
code. Most applications use a single UI thread, although in some situations it 
is best to use several.<SPAN style="FONT-FAMILY: 宋体">”后者便是所谓的</SPAN>UI<SPAN 
style="FONT-FAMILY: 宋体">线程，是我们需要经常面对的。</SPAN></P>
<P><STRONG></STRONG>&nbsp;</P>
<P 
style="MARGIN-LEFT: 18pt; TEXT-INDENT: -18pt"><STRONG>2，</STRONG><STRONG>Dispatcher</STRONG></P>
<P>WPF<SPAN style="FONT-FAMILY: 宋体">规定了（事实上在</SPAN>.net2.0<SPAN 
style="FONT-FAMILY: 宋体">中便已规定了）</SPAN>UI<SPAN 
style="FONT-FAMILY: 宋体">元素只能由创建该元素的线程来访问。比如我们从新开的一个线程中访问主界面中的元素会出现运行时的异常。</SPAN>Dispatcher<SPAN 
style="FONT-FAMILY: 宋体">来维持着这一规定，并组织着消息循环。</SPAN>Dispatcher<SPAN 
style="FONT-FAMILY: 宋体">负责检测访问对象的线程与对象创建线程是否一致，不一致则抛出异常。值得一提的是，</SPAN>Dispatcher<SPAN 
style="FONT-FAMILY: 宋体">的消息循环中的</SPAN>Work Item<SPAN 
style="FONT-FAMILY: 宋体">是有优先级的，这可以让高优先级的项能有更多的工作时间。比如界面绘制比处理用户输入的优先级要高，这使得界面动画更加流畅。这也就是为什么，我们在调用</SPAN>Dispatcher.Invoke 
( DispatcherPriority,…) <SPAN style="FONT-FAMILY: 宋体">与</SPAN>Dispatcher. 
BeginInvoke (DispatcherPriority,…)<SPAN 
style="FONT-FAMILY: 宋体">要传入一个优先级参数的原因。下面是对各个优先级的说明：</SPAN></P>
<TABLE cellSpacing=0 cellPadding=0 border=1>
  <TBODY>
  <TR>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt">
      <P style="TEXT-ALIGN: center" align=center><STRONG><SPAN 
      style="FONT-FAMILY: 宋体">优先级</SPAN></STRONG></P></TD>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt">
      <P style="TEXT-ALIGN: center" align=center><STRONG><SPAN 
      style="FONT-FAMILY: 宋体">说明</SPAN></STRONG></P></TD></TR>
  <TR>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">Inactive</SPAN></P></TD>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">工作项目已排队但未处理。 </SPAN></P></TD></TR>
  <TR>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">SystemIdle</SPAN></P></TD>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">仅当系统空闲时才将工作项目调度到 UI 
      线程。这是实际得到处理的项目的最低优先级。</SPAN></P></TD></TR>
  <TR>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">ApplicationIdle</SPAN></P></TD>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">仅当应用程序本身空闲时才将工作项目调度到 UI 线程。</SPAN></P></TD></TR>
  <TR>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">ContextIdle</SPAN></P></TD>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">仅在优先级更高的工作项目得到处理后才将工作项目调度到 UI 线程。</SPAN></P></TD></TR>
  <TR>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">Background</SPAN></P></TD>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">在所有布局、呈现和输入项目都得到处理后才将工作项目调度到 UI 
  线程。</SPAN></P></TD></TR>
  <TR>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">Input</SPAN></P></TD>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">以与用户输入相同的优先级将工作项目调度到 UI 线程。</SPAN></P></TD></TR>
  <TR>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">Loaded</SPAN></P></TD>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">在所有布局和呈现都完成后才将工作项目调度到 UI 线程。 </SPAN></P></TD></TR>
  <TR>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">Render</SPAN></P></TD>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">以与呈现引擎相同的优先级将工作项目调度到 UI 线程。</SPAN></P></TD></TR>
  <TR>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">DataBind</SPAN></P></TD>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">以与数据绑定相同的优先级将工作项目调度到 UI 线程。</SPAN></P></TD></TR>
  <TR>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">Normal</SPAN></P></TD>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">以正常优先级将工作项目调度到 UI 
      线程。这是调度大多数应用程序工作项目时的优先级。</SPAN></P></TD></TR>
  <TR>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">Send</SPAN></P></TD>
    <TD 
    style="PADDING-RIGHT: 2.25pt; PADDING-LEFT: 2.25pt; PADDING-BOTTOM: 2.25pt; PADDING-TOP: 2.25pt" 
    vAlign=top>
      <P style="TEXT-ALIGN: left" align=left><SPAN 
      style="FONT-FAMILY: 宋体">以最高优先级将工作项目调度到 UI 线程。 
</SPAN></P></TD></TR></TBODY></TABLE>
<P><SPAN style="FONT-FAMILY: 宋体">上面提到了</SPAN>Dispatcher<SPAN 
style="FONT-FAMILY: 宋体">维持着一个规矩“只有创建该对象的线程可以访问该对象”。这里的对象不仅仅是指一些</SPAN>UI<SPAN 
style="FONT-FAMILY: 宋体">控件（比如</SPAN>Button<SPAN 
style="FONT-FAMILY: 宋体">），而是所以的派生于</SPAN>DispatcherObject<SPAN 
style="FONT-FAMILY: 宋体">类的对象。我们做一个小小的试验，假设有如下这样一个类：<BR></SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN 
style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'"></P>
<DIV 
style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">public</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">class</SPAN><SPAN 
style="COLOR: #000000">&nbsp;Data<BR><IMG id=Codehighlighter1_26_272_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_26_272_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_26_272_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_26_272_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_26_272_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_26_272_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_26_272_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_26_272_Open_Text').style.display='inline';" 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_26_272_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_26_272_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">private</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">object</SPAN><SPAN 
style="COLOR: #000000">&nbsp;theData&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">;<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">public</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">object</SPAN><SPAN 
style="COLOR: #000000">&nbsp;TheData<BR><IMG 
id=Codehighlighter1_106_270_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_106_270_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_106_270_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_106_270_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockStart.gif" 
align=top><IMG id=Codehighlighter1_106_270_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_106_270_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_106_270_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_106_270_Open_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedSubBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_106_270_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_106_270_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">get</SPAN><SPAN style="COLOR: #000000"><BR><IMG 
id=Codehighlighter1_136_183_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_136_183_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_136_183_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_136_183_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockStart.gif" 
align=top><IMG id=Codehighlighter1_136_183_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_136_183_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_136_183_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_136_183_Open_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedSubBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_136_183_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_136_183_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">return</SPAN><SPAN 
style="COLOR: #000000">&nbsp;theData;<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">set</SPAN><SPAN style="COLOR: #000000"><BR><IMG 
id=Codehighlighter1_212_260_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_212_260_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_212_260_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_212_260_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockStart.gif" 
align=top><IMG id=Codehighlighter1_212_260_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_212_260_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_212_260_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_212_260_Open_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedSubBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_212_260_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_212_260_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;theData&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;value;<BR><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockEnd.gif" 
align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top></SPAN></DIV>
<P style="TEXT-ALIGN: left" align=left></SPAN><SPAN 
style="FONT-FAMILY: 宋体">我们在UI线程中声明其一个实例，并在新线程中使用它：</SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN 
style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'"></P>
<DIV 
style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">private</SPAN><SPAN 
style="COLOR: #000000">&nbsp;Data&nbsp;myData&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">new</SPAN><SPAN 
style="COLOR: #000000">&nbsp;Data();<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">private</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">void</SPAN><SPAN 
style="COLOR: #000000">&nbsp;btnTest_Click(</SPAN><SPAN 
style="COLOR: #0000ff">object</SPAN><SPAN 
style="COLOR: #000000">&nbsp;sender,&nbsp;RoutedEventArgs&nbsp;e)<BR><IMG 
id=Codehighlighter1_113_265_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_113_265_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_113_265_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_113_265_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_113_265_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_113_265_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_113_265_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_113_265_Open_Text').style.display='inline';" 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_113_265_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_113_265_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ThreadStart&nbsp;ts&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">new</SPAN><SPAN 
style="COLOR: #000000">&nbsp;ThreadStart(</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN 
style="COLOR: #000000">.UpdateData);<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread&nbsp;newThread&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">new</SPAN><SPAN 
style="COLOR: #000000">&nbsp;Thread(ts);<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newThread.Start();<BR><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">private</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">void</SPAN><SPAN 
style="COLOR: #000000">&nbsp;UpdateData()<BR><IMG 
id=Codehighlighter1_309_357_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_309_357_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_309_357_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_309_357_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_309_357_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_309_357_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_309_357_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_309_357_Open_Text').style.display='inline';" 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_309_357_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_309_357_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN 
style="COLOR: #000000">.myData.TheData&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #800080">5</SPAN><SPAN style="COLOR: #000000">;<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top></SPAN></DIV>
<P style="TEXT-ALIGN: left" align=left>&nbsp;</SPAN><SPAN 
style="FONT-FAMILY: 宋体">OK</SPAN><SPAN 
style="FONT-FAMILY: 宋体">，不会有问题（我们暂不考虑跨多个线程访问是否安全等）。<BR>&nbsp; </SPAN><SPAN 
style="FONT-FAMILY: 宋体">但是，如果我们让Data类继承于DependencyObject类（其又继承于DispatcherObject类，在WPF中我们会经常这样做，因为我们要使用Dependency 
Property）：</P>
<DIV 
style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">public</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">class</SPAN><SPAN 
style="COLOR: #000000">&nbsp;Data&nbsp;:&nbsp;DependencyObject<BR><IMG 
id=Codehighlighter1_45_479_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_45_479_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_45_479_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_45_479_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_45_479_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_45_479_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_45_479_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_45_479_Open_Text').style.display='inline';" 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_45_479_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_45_479_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">public</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">object</SPAN><SPAN 
style="COLOR: #000000">&nbsp;TheData<BR><IMG 
id=Codehighlighter1_85_292_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_85_292_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_85_292_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_85_292_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockStart.gif" 
align=top><IMG id=Codehighlighter1_85_292_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_85_292_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_85_292_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_85_292_Open_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedSubBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_85_292_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_85_292_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">get</SPAN><SPAN style="COLOR: #000000"><BR><IMG 
id=Codehighlighter1_115_188_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_115_188_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_115_188_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_115_188_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockStart.gif" 
align=top><IMG id=Codehighlighter1_115_188_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_115_188_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_115_188_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_115_188_Open_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedSubBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_115_188_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_115_188_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">return</SPAN><SPAN 
style="COLOR: #000000">&nbsp;(</SPAN><SPAN 
style="COLOR: #0000ff">object</SPAN><SPAN 
style="COLOR: #000000">)GetValue(TheDataProperty);<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">set</SPAN><SPAN style="COLOR: #000000"><BR><IMG 
id=Codehighlighter1_217_282_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_217_282_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_217_282_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_217_282_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockStart.gif" 
align=top><IMG id=Codehighlighter1_217_282_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_217_282_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_217_282_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_217_282_Open_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedSubBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_217_282_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_217_282_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SetValue(TheDataProperty,&nbsp;value);<BR><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">public</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">static</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">readonly</SPAN><SPAN 
style="COLOR: #000000">&nbsp;DependencyProperty&nbsp;TheDataProperty&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DependencyProperty.Register(</SPAN><SPAN 
style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">TheData</SPAN><SPAN 
style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">typeof</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN 
style="COLOR: #0000ff">object</SPAN><SPAN 
style="COLOR: #000000">),&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">typeof</SPAN><SPAN 
style="COLOR: #000000">(Data),&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">new</SPAN><SPAN 
style="COLOR: #000000">&nbsp;UIPropertyMetadata(</SPAN><SPAN 
style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">));<BR><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top></SPAN></DIV>
<P style="TEXT-ALIGN: left" align=left></SPAN><SPAN 
style="FONT-FAMILY: 宋体">如果现在还按照以前的使用方式（在UI线程中声明其一个实例，并在新线程中使用它）来使用，你就会收到一个“由于其他线程拥有此对象，因此调用线程无法对其进行访问。”的System.InvalidOperationException。正确使用它的方式是使用Dispatcher的Invoke或BeginInvoke方法：</P>
<DIV 
style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top><SPAN 
style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">private</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">void</SPAN><SPAN 
style="COLOR: #000000">&nbsp;UpdateData()<BR><IMG 
id=Codehighlighter1_42_399_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_42_399_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_42_399_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_42_399_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_42_399_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_42_399_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_42_399_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_42_399_Open_Text').style.display='inline';" 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_42_399_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_42_399_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN 
style="COLOR: #000000">.myData.Dispatcher.CheckAccess())<BR><IMG 
id=Codehighlighter1_110_166_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_110_166_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_110_166_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_110_166_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockStart.gif" 
align=top><IMG id=Codehighlighter1_110_166_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_110_166_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_110_166_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_110_166_Open_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedSubBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_110_166_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_110_166_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN 
style="COLOR: #000000">.myData.TheData&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #800080">5</SPAN><SPAN style="COLOR: #000000">;<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000"><BR><IMG 
id=Codehighlighter1_196_389_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_196_389_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_196_389_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_196_389_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockStart.gif" 
align=top><IMG id=Codehighlighter1_196_389_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_196_389_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_196_389_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_196_389_Open_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedSubBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_196_389_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_196_389_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN 
style="COLOR: #000000">.myData.Dispatcher.Invoke(DispatcherPriority.Normal,&nbsp;(ThreadStart)</SPAN><SPAN 
style="COLOR: #0000ff">delegate</SPAN><SPAN style="COLOR: #000000"><BR><IMG 
id=Codehighlighter1_309_373_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_309_373_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_309_373_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_309_373_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockStart.gif" 
align=top><IMG id=Codehighlighter1_309_373_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_309_373_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_309_373_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_309_373_Open_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedSubBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_309_373_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_309_373_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN 
style="COLOR: #000000">.myData.TheData&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #800080">5</SPAN><SPAN style="COLOR: #000000">;<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000">);<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top></SPAN></DIV>
<P style="TEXT-ALIGN: left" align=left></SPAN><SPAN 
style="FONT-FAMILY: 宋体">更多的，你可以访问这篇Blog：<A 
href="http://www.cnblogs.com/zhouyinhui/archive/2007/05/10/742134.html">http://www.cnblogs.com/zhouyinhui/archive/2007/05/10/742134.html</A></SPAN></P>
<P style="MARGIN-LEFT: 18pt; TEXT-INDENT: -18pt; TEXT-ALIGN: left" 
align=left><STRONG><SPAN style="FONT-FAMILY: 宋体">3，</SPAN></STRONG><STRONG><SPAN 
style="FONT-FAMILY: 宋体">对于阻塞的操作，不一定需要开启新线程</SPAN></STRONG></P>
<P style="TEXT-ALIGN: left" align=left><SPAN 
style="FONT-FAMILY: 宋体">当我们遇到某个费时的操作是，第一反映往往是开启一个新线程，然后在后台去处理它，以便不阻塞我们的用户界面。当然，这是正确的想法。当并不是所有的都需如此。仔细想想界面阻塞的原因，我们知道其是由于时间被消耗在某个费时的Work 
Item上了，而那些处理用户界面的Work 
Item还在那里苦苦等候。So，我们只要别让他们苦苦等候就可以了，只要用户有界面操作我们就处理，线程上的其他空闲时间来处理我们的复杂操作。我们将复杂的费时的操作细化成很多不费时的小操作，在这些小操作之间的空隙处我们来处理相应用户界面的操作</SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN style="FONT-FAMILY: 宋体">阻塞的情况如下, 
MouseUp与MouseLeave会被阻塞：</SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN 
style="FONT-FAMILY: 宋体">（MouseDown）-&gt;(费时的，复杂操作)-&gt;（MouseUp）-&gt;(MouseLeave)…</SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN 
style="FONT-FAMILY: 宋体">细化后的情况如下，MouseUp与MouseLeave不会被阻塞：</SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN 
style="FONT-FAMILY: 宋体">（MouseDown）-&gt;(不费时的，小操作，复杂操作的1/n)-&gt;（MouseUp）-&gt;(不费时的，小操作，复杂操作的1/n) 
-&gt; (MouseLeave)…</SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN 
style="FONT-FAMILY: 宋体">举一个简单的例子，假定我们的主界面上要显示一个数字，其为Window1的CurrentNum属性，我们已经将界面上的某个TextBlock与其绑定了起来：</SPAN><SPAN 
style="FONT-FAMILY: 宋体"></P>
<DIV 
style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top><SPAN 
style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">&lt;</SPAN><SPAN 
style="COLOR: #800000">TextBlock&nbsp;</SPAN><SPAN 
style="COLOR: #ff0000">x:Name</SPAN><SPAN 
style="COLOR: #0000ff">="textBlock_ShowNum"</SPAN><SPAN 
style="COLOR: #ff0000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Text</SPAN><SPAN 
style="COLOR: #0000ff">="{Binding&nbsp;ElementName=window1,Path=CurrentNum}"</SPAN><SPAN 
style="COLOR: #ff0000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VerticalAlignment</SPAN><SPAN 
style="COLOR: #0000ff">="Center"</SPAN><SPAN style="COLOR: #ff0000"><BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HorizontalAlignment</SPAN><SPAN 
style="COLOR: #0000ff">="Center"</SPAN><SPAN 
style="COLOR: #ff0000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top></SPAN></DIV>
<P style="TEXT-ALIGN: left" 
align=left>当我们点击界面上的一个按钮后，要求该数字被不停的累加，直到再次点击该按钮是停止.实际效果相当于：</SPAN><SPAN 
style="FONT-FAMILY: 宋体"></P>
<DIV 
style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top><SPAN 
style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">while</SPAN><SPAN 
style="COLOR: #000000">&nbsp;(</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN 
style="COLOR: #000000">.IsCalculating)<BR><IMG 
id=Codehighlighter1_51_101_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_51_101_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_51_101_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_51_101_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_51_101_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_51_101_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_51_101_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_51_101_Open_Text').style.display='inline';" 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_51_101_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_51_101_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN 
style="COLOR: #000000">.CurrentNum</SPAN><SPAN 
style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">;<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top></SPAN></DIV>
<P style="TEXT-ALIGN: left" 
align=left>如果我们直接按照上面的While语句来书写程序，明显，当用户点击按钮后，整个线程将在这里被堵死，界面得不到更新，用户也没有办法再次点击按钮来停止这个循环，遭透了。</SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN 
style="FONT-FAMILY: 宋体">既不开启新线程又不阻塞界面应该怎么办呢？</SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN 
style="FONT-FAMILY: 宋体">我们知道this.CurrentNum++;语句以及更新绑定到CurrentNum属性的TextBlock并不耗费时间的，耗费时间的是他们的累加而成的死循环，所以，我们将这个循环分解成无数个仅仅由this.Current++语句组成的小方法，并在这些小方法的之间来处理用户界面：<BR></P>
<DIV 
style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top><SPAN style="COLOR: #0000ff">public</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">delegate</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">void</SPAN><SPAN 
style="COLOR: #000000">&nbsp;NormalDelegate();<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">void</SPAN><SPAN 
style="COLOR: #000000">&nbsp;button_StartOrStop_Click(</SPAN><SPAN 
style="COLOR: #0000ff">object</SPAN><SPAN 
style="COLOR: #000000">&nbsp;sender,&nbsp;RoutedEventArgs&nbsp;e)<BR><IMG 
id=Codehighlighter1_120_368_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_120_368_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_120_368_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_120_368_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_120_368_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_120_368_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_120_368_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_120_368_Open_Text').style.display='inline';" 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_120_368_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_120_368_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN 
style="COLOR: #000000">.IsCalculating)<BR><IMG 
id=Codehighlighter1_170_358_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_170_358_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_170_358_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_170_358_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockStart.gif" 
align=top><IMG id=Codehighlighter1_170_358_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_170_358_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_170_358_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_170_358_Open_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedSubBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_170_358_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_170_358_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NormalDelegate&nbsp;calNumDelegate&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">new</SPAN><SPAN 
style="COLOR: #000000">&nbsp;NormalDelegate(</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.CalNum);<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN 
style="COLOR: #000000">.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle,&nbsp;calNumDelegate);<BR><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">private</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">void</SPAN><SPAN 
style="COLOR: #000000">&nbsp;CalNum()<BR><IMG 
id=Codehighlighter1_408_688_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_408_688_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_408_688_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_408_688_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_408_688_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_408_688_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_408_688_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_408_688_Open_Text').style.display='inline';" 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_408_688_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_408_688_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN 
style="COLOR: #000000">.CurrentNum</SPAN><SPAN 
style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">;<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN 
style="COLOR: #000000">.IsCalculating)<BR><IMG 
id=Codehighlighter1_490_678_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_490_678_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_490_678_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_490_678_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockStart.gif" 
align=top><IMG id=Codehighlighter1_490_678_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_490_678_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_490_678_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_490_678_Open_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedSubBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_490_678_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_490_678_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NormalDelegate&nbsp;calNumDelegate&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">new</SPAN><SPAN 
style="COLOR: #000000">&nbsp;NormalDelegate(</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.CalNum);<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN 
style="COLOR: #000000">.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle,&nbsp;calNumDelegate);<BR><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedSubBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top></SPAN></DIV>
<P style="TEXT-ALIGN: left" align=left></SPAN><SPAN 
style="FONT-FAMILY: 宋体">上面的两段代码可以简单地如下示意：</SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN style="FONT-FAMILY: 宋体">阻塞的情况如下, 
MouseUp与MouseLeave会被阻塞：</SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN 
style="FONT-FAMILY: 宋体">（MouseDown）-&gt;(费时的While（true）)-&gt;（MouseUp）-&gt;(MouseLeave)…</SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN 
style="FONT-FAMILY: 宋体">细化后的情况如下，MouseUp与MouseLeave不会被阻塞：</SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN 
style="FONT-FAMILY: 宋体">（MouseDown）-&gt;(不费时的CalNum)-&gt;（MouseUp）-&gt;(不费时的CalNum) 
-&gt; (MouseLeave)…</SPAN></P>
<P style="MARGIN-LEFT: 18pt; TEXT-INDENT: -18pt; TEXT-ALIGN: left" 
align=left><STRONG><SPAN style="FONT-FAMILY: 宋体">4，</SPAN></STRONG><STRONG><SPAN 
style="FONT-FAMILY: 宋体">用Delegate.Invoke（）或Delegate.BeginInvoke（）来开启新线程</SPAN></STRONG></P>
<P style="TEXT-ALIGN: left" align=left><SPAN style="FONT-FAMILY: 宋体">除了new 
一个Thread对象外，使用Delegate的Invoke或BeginInvoke方法也可以开启新的线程。</SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN 
style="FONT-FAMILY: 宋体">假设有下面这一个很费时的方法，我们应该如何使用Delegate来改造呢</SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN style="FONT-FAMILY: 宋体"></P>
<DIV 
style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top><SPAN 
style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">private</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">void</SPAN><SPAN 
style="COLOR: #000000">&nbsp;TheHugeMethod()<BR><IMG 
id=Codehighlighter1_45_149_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_45_149_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_45_149_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_45_149_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_45_149_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_45_149_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_45_149_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_45_149_Open_Text').style.display='inline';" 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_45_149_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_45_149_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.Sleep(</SPAN><SPAN 
style="COLOR: #800080">2000</SPAN><SPAN style="COLOR: #000000">);<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN 
style="COLOR: #000000">.button_Test.Content&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">OK!!!</SPAN><SPAN 
style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top></SPAN></DIV>
<P style="TEXT-ALIGN: left" align=left>首先，我们声明一个可以用于TheHugeMethod方法的代理：</P>
<DIV 
style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top><SPAN style="COLOR: #0000ff">public</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">delegate</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">void</SPAN><SPAN 
style="COLOR: #000000">&nbsp;NormalMethod();<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top></SPAN></DIV>
<P style="TEXT-ALIGN: left" align=left></SPAN><SPAN 
style="FONT-FAMILY: 宋体">然后对TheHugeMethod构造一个NormalMethod类型的对象，并调用其Invoke方法（同步调用）或BeginInvoke方法（异步调用）</P>
<DIV 
style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top><SPAN 
style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">void</SPAN><SPAN 
style="COLOR: #000000">&nbsp;button_Test_Click(</SPAN><SPAN 
style="COLOR: #0000ff">object</SPAN><SPAN 
style="COLOR: #000000">&nbsp;sender,&nbsp;RoutedEventArgs&nbsp;e)<BR><IMG 
id=Codehighlighter1_73_224_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_73_224_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_73_224_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_73_224_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_73_224_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_73_224_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_73_224_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_73_224_Open_Text').style.display='inline';" 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_73_224_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_73_224_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NormalMethod&nbsp;hugeMethodDelegate&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">new</SPAN><SPAN 
style="COLOR: #000000">&nbsp;NormalMethod(</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN 
style="COLOR: #000000">.TheHugeMethod);<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hugeMethodDelegate.BeginInvoke(</SPAN><SPAN 
style="COLOR: #0000ff">null</SPAN><SPAN 
style="COLOR: #000000">,&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">);<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top></SPAN></DIV>
<P style="TEXT-ALIGN: left" align=left></SPAN><SPAN 
style="FONT-FAMILY: 宋体">由于是开启了新的线程，所以TheHugeMethod方法中对this.button_Test控件的调用语句也得改造一下：</SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN></P>
<P style="TEXT-ALIGN: left" align=left></P>
<DIV 
style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><STRONG><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top></STRONG><SPAN 
style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">private</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">void</SPAN><SPAN 
style="COLOR: #000000">&nbsp;TheHugeMethod()<BR><IMG 
id=Codehighlighter1_45_352_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_45_352_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_45_352_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_45_352_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_45_352_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_45_352_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_45_352_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_45_352_Open_Text').style.display='inline';" 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_45_352_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_45_352_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.Sleep(</SPAN><SPAN 
style="COLOR: #800080">2000</SPAN><SPAN style="COLOR: #000000">);<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #008000">//</SPAN><SPAN 
style="COLOR: #008000">will&nbsp;crash<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #008000">//</SPAN><SPAN 
style="COLOR: #008000">this.button_Test.Content&nbsp;=&nbsp;"OK!!!";</SPAN><SPAN 
style="COLOR: #008000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NormalMethod&nbsp;updateUIDelegate&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">new</SPAN><SPAN 
style="COLOR: #000000">&nbsp;NormalMethod(</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN 
style="COLOR: #000000">.UpdateUI);<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN 
style="COLOR: #000000">.button_Test.Dispatcher.BeginInvoke(DispatcherPriority.Normal,&nbsp;updateUIDelegate);<BR><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">private</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">void</SPAN><SPAN 
style="COLOR: #000000">&nbsp;UpdateUI()<BR><IMG 
id=Codehighlighter1_394_454_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_394_454_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_394_454_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_394_454_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_394_454_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_394_454_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_394_454_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_394_454_Open_Text').style.display='inline';" 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_394_454_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_394_454_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">this</SPAN><SPAN 
style="COLOR: #000000">.button_Test.Content&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #800000">"</SPAN><SPAN 
style="COLOR: #800000">OK!!!&nbsp;</SPAN><SPAN 
style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><STRONG><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top></STRONG></SPAN></DIV>
<P style="TEXT-ALIGN: left" 
align=left><BR><STRONG>5，在新线程中执行消息循环</STRONG></SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN 
style="FONT-FAMILY: 宋体">一般情况下我们不需要在新线程中执行消息循环了，因为我们常常是在新线程中执行一些后台操作而不需要用户在新线程中执行UI操作（比如我们在新线程中从网络上下载一些数据然后UI线程来显示这些数据）。当有时新线程却是需要消息循环的，最简单的例子是操作系统的“资源管理器”，每一个资源管理器窗口都在一个单独的线程中（它们都在同一个进程中）。</SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN 
style="FONT-FAMILY: 宋体">但当你按照如下方式编写代码来新建一个资源管理器窗口时，会出问题：</SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN style="FONT-FAMILY: 宋体"></P>
<DIV 
style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top><SPAN 
style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">private</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">void</SPAN><SPAN 
style="COLOR: #000000">&nbsp;button_NewWindow_Click(</SPAN><SPAN 
style="COLOR: #0000ff">object</SPAN><SPAN 
style="COLOR: #000000">&nbsp;sender,&nbsp;RoutedEventArgs&nbsp;e)<BR><IMG 
id=Codehighlighter1_86_337_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_86_337_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_86_337_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_86_337_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_86_337_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_86_337_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_86_337_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_86_337_Open_Text').style.display='inline';" 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_86_337_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_86_337_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread&nbsp;newWindowThread&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">new</SPAN><SPAN 
style="COLOR: #000000">&nbsp;Thread(</SPAN><SPAN 
style="COLOR: #0000ff">new</SPAN><SPAN 
style="COLOR: #000000">&nbsp;ThreadStart(ThreadStartingPoint));<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newWindowThread.SetApartmentState(ApartmentState.STA);<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newWindowThread.IsBackground&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">;<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newWindowThread.Start();<BR><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">private</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">void</SPAN><SPAN 
style="COLOR: #000000">&nbsp;ThreadStartingPoint()<BR><IMG 
id=Codehighlighter1_390_478_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_390_478_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_390_478_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_390_478_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_390_478_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_390_478_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_390_478_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_390_478_Open_Text').style.display='inline';" 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_390_478_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_390_478_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Window1&nbsp;newWindow&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">new</SPAN><SPAN 
style="COLOR: #000000">&nbsp;Window1();<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newWindow.Show();<BR><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top></SPAN></DIV>
<P style="TEXT-ALIGN: left" 
align=left>问题是newWindow闪现一下就消失了。因为该新窗口没有进入消息循环，当newWindow.Show()方法执行完毕后，新线程的一切都结束了。</SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN 
style="FONT-FAMILY: 宋体">正确的方法是在newWindow.Show();方法后加入Dispatcher.Run（）语句，其会将主执行帧推入该Dispatcher的消息循环中。</SPAN><SPAN><FONT 
face="Courier New"></P>
<DIV 
style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top><SPAN 
style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">private</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">void</SPAN><SPAN 
style="COLOR: #000000">&nbsp;ThreadStartingPoint()<BR><IMG 
id=Codehighlighter1_51_194_Open_Image 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_51_194_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_51_194_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_51_194_Closed_Text').style.display='inline';" 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_51_194_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; document.getElementById('Codehighlighter1_51_194_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_51_194_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_51_194_Open_Text').style.display='inline';" 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ContractedBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN 
id=Codehighlighter1_51_194_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_51_194_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Window1&nbsp;newWindow&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">new</SPAN><SPAN 
style="COLOR: #000000">&nbsp;Window1();<BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newWindow.Show();<BR><IMG 
alt="" src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/InBlock.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Windows.Threading.Dispatcher.Run();<BR><IMG 
alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ExpandedBlockEnd.gif" 
align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN 
style="COLOR: #000000"><BR><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/None.gif" 
align=top></SPAN></DIV>
<P></FONT></SPAN><SPAN><STRONG>6，BackgroundWorker实质是：基于事件的异步模式</STRONG></SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN 
style="FONT-FAMILY: 宋体">在多线程编程中，最爽的莫过于.net 
提供了BackgroundWorker类了。其可以：<BR></SPAN><SPAN 
style="FONT-FAMILY: 宋体">“在后台”执行耗时任务（例如下载和数据库操作），但不会中断您的应用程序。<BR></SPAN><SPAN 
style="FONT-FAMILY: 宋体">同时执行多个操作，每个操作完成时都会接到通知。<BR></SPAN><SPAN 
style="FONT-FAMILY: 宋体">等待资源变得可用，但不会停止（“挂起”）您的应用程序。<BR></SPAN><SPAN 
style="FONT-FAMILY: 宋体">使用熟悉的事件和委托模型与挂起的异步操作通信。</SPAN></P>
<P style="TEXT-ALIGN: left" align=left><SPAN 
style="FONT-FAMILY: 宋体">我想大家对BackgroundWorker亦是再熟悉不过了，这里就不多做介绍了，另外“基于事件的异步模式”是WinForm的内容，但在WPF中完美运用（原因是WPF用DispatcherSynchronizationContext扩展了SynchronizationContext），可以参见MSDN“Event-based 
Asynchronous Pattern Overview”<BR><BR></SPAN></P>
<DIV id=digg_block>
<DIV id=div_digg>
<DIV class=diggit onclick=DiggIt(1055261,18579,1)><SPAN class=diggnum 
id=digg_count_1055261>0</SPAN> </DIV>
<DIV class=buryit onclick=DiggIt(1055261,18579,2)><SPAN class=burynum 
id=bury_count_1055261>0</SPAN> </DIV>
<DIV class=clear></DIV><SPAN id=span_isdigged_1055261 
style="DISPLAY: none">0</SPAN> 
<DIV class=diggword id=digg_word_1055261>(请您对文章做出评价)</DIV></DIV></DIV>
<DIV class=clear></DIV>
<DIV id=post_next_prev><A 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/25/1052717.html">« 
</A>上一篇：<A title="发布于2008-01-25 10:59" 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/25/1052717.html">WPF in 
Finance</A><BR><A 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/30/1058363.html">» 
</A>下一篇：<A title="发布于2008-01-30 10:30" 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/30/1058363.html">WPF高手：站出来，Show出来</A><BR></DIV>
<SCRIPT src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/google_service.js" 
type=text/javascript></SCRIPT>

<SCRIPT type=text/javascript>
    try {
        GS_googleAddAdSenseService("ca-pub-4210569241504288");
        GS_googleEnableAllServices();
    }
    catch (e) { }
</SCRIPT>

<SCRIPT type=text/javascript>
    try {
        GA_googleAddSlot("ca-pub-4210569241504288", "cnblogs_blogpost_body");
        GA_googleAddSlot("ca-pub-4210569241504288", "cnblogs_commentbox_up");
        GA_googleAddSlot("ca-pub-4210569241504288", "cnblogs_blogpost_bottom");
    }
    catch (e) { }
</SCRIPT>

<SCRIPT type=text/javascript>
    try {
        GA_googleFetchAds();
    } catch (e) { }
</SCRIPT>

<SCRIPT type=text/javascript>
    var blog_ad_has_shown = false;
</SCRIPT>
</DIV>
<DIV class=postDesc>posted @ 2008-01-27 21:52 <A 
href="http://www.cnblogs.com/zhouyinhui/">周银辉</A> 阅读(4092) <A 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#commentform">评论(9)</A> 
&nbsp;<A 
href="http://www.cnblogs.com/zhouyinhui/admin/EditPosts.aspx?postid=1055261">编辑</A> 
<A href="http://www.cnblogs.com/zhouyinhui/AddToFavorite.aspx?id=1055261">收藏</A> 
<A onclick="PutInWz();return false;" 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#">网摘</A> 
所属分类: <A 
href="http://www.cnblogs.com/zhouyinhui/category/86467.html">WPF</A></DIV></DIV><IMG 
height=1 src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/1055261.jpg" 
width=1> <!--
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description
rdf:about="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html"
dc:identifier="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html"
dc:title=""
trackback:ping="http://www.cnblogs.com/zhouyinhui/services/trackbacks/1055261.aspx" />
</rdf:RDF>
--></DIV><!--end: topics 文章、评论容器--><A name=pagedcomment></A><!--done--><BR>
<DIV class=feedback_area_title>发表评论</DIV>
<DIV class=feedbackNoItems><SPAN id=span_comment_maxid 
style="DISPLAY: none">1617320</SPAN></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle>
<DIV class=feedbackManage>&nbsp;&nbsp;<A 
onclick='ReplyComment("thinboy",1055310,"")' 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#commentform">回复</A>&nbsp;&nbsp;<A 
onclick='QuoteComment(1055310,"")' 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#commentform">引用</A>&nbsp;&nbsp;<A 
id=Comments1_CommentList_ctl00_DeleteLink 
href="javascript:__doPostBack('Comments1$CommentList$ctl00$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=Comments1_CommentList_ctl00_EditLink CausesValidation="False"></A> </DIV><A 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#1055310">#1楼</A><A 
id=comment_anchor_1055310 name=1055310></A>2008-01-27 22:43 | <A 
id=Comments1_CommentList_ctl00_NameLink 
href="http://www.cnitblog.com/r.aspx?url=http://www.51zone.org" target=_blank 
rel=nofllow>thinboy[未注册用户]</A> </DIV>
<DIV class=feedbackCon><SPAN class=blog_comment_body 
id=comment_body_1055310>学习了</SPAN><BR></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle>
<DIV class=feedbackManage>&nbsp;&nbsp;<A 
onclick='ReplyComment("SolidWorks",1055795,"")' 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#commentform">回复</A>&nbsp;&nbsp;<A 
onclick='QuoteComment(1055795,"")' 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#commentform">引用</A>&nbsp;&nbsp;<A 
id=Comments1_CommentList_ctl01_DeleteLink 
href="javascript:__doPostBack('Comments1$CommentList$ctl01$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=Comments1_CommentList_ctl01_EditLink CausesValidation="False"></A> </DIV><A 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#1055795">#2楼</A><A 
id=comment_anchor_1055795 name=1055795></A>2008-01-28 11:02 | <A 
id=Comments1_CommentList_ctl01_NameLink 
href="http://www.cnitblog.com/r.aspx?url=http://www.cadvip.com" target=_blank 
rel=nofllow>SolidWorks[未注册用户]</A> </DIV>
<DIV class=feedbackCon><SPAN class=blog_comment_body 
id=comment_body_1055795>楼主的文章，都比较强，好好学习一下！</SPAN><BR></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle>
<DIV class=feedbackManage>&nbsp;&nbsp;<A 
onclick='ReplyComment("周银辉",1055856,"6wrAZKGOIyXkPOlMmEb0u06FSn0oZ2BVtvmaruwrBUq7rCo85sV5Jw==")' 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#commentform">回复</A>&nbsp;&nbsp;<A 
onclick='QuoteComment(1055856,"6wrAZKGOIyXkPOlMmEb0u06FSn0oZ2BVtvmaruwrBUq7rCo85sV5Jw==")' 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#commentform">引用</A>&nbsp;&nbsp;<A 
title=查看该作者发表过的评论 
href="http://www.cnblogs.com/CommentsByAuthor.aspx?author=%e5%91%a8%e9%93%b6%e8%be%89" 
target=_blank>查看</A>&nbsp;&nbsp;<A id=Comments1_CommentList_ctl02_DeleteLink 
href="javascript:__doPostBack('Comments1$CommentList$ctl02$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=Comments1_CommentList_ctl02_EditLink CausesValidation="False"></A> </DIV><A 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#1055856">#3楼</A><A 
id=comment_anchor_1055856 name=1055856></A>[<SPAN 
class=louzhu>楼主</SPAN>]2008-01-28 11:31 | <A 
id=Comments1_CommentList_ctl02_NameLink 
href="http://www.cnblogs.com/zhouyinhui/" target=_blank>周银辉</A>&nbsp;<A 
class=sendMsg2This title=给此人发送站内短消息 
href="http://space.cnblogs.com/msg/send/å¨é¶è¾">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</A> 
</DIV>
<DIV class=feedbackCon><SPAN class=blog_comment_body 
id=comment_body_1055856>@SolidWorks <BR>呵呵...谢谢</SPAN><BR></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle>
<DIV class=feedbackManage>&nbsp;&nbsp;<A 
onclick='ReplyComment("jillzhang",1056141,"X93u9YlEp3MkgR0IyqZLTsD+58qH9vSrX1s+epmNjz0VPvXgHqSu4Q==")' 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#commentform">回复</A>&nbsp;&nbsp;<A 
onclick='QuoteComment(1056141,"X93u9YlEp3MkgR0IyqZLTsD+58qH9vSrX1s+epmNjz0VPvXgHqSu4Q==")' 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#commentform">引用</A>&nbsp;&nbsp;<A 
title=查看该作者发表过的评论 
href="http://www.cnblogs.com/CommentsByAuthor.aspx?author=jillzhang" 
target=_blank>查看</A>&nbsp;&nbsp;<A id=Comments1_CommentList_ctl03_DeleteLink 
href="javascript:__doPostBack('Comments1$CommentList$ctl03$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=Comments1_CommentList_ctl03_EditLink CausesValidation="False"></A> </DIV><A 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#1056141">#4楼</A><A 
id=comment_anchor_1056141 name=1056141></A>2008-01-28 14:08 | <A 
id=Comments1_CommentList_ctl03_NameLink href="http://www.cnblogs.com/jillzhang/" 
target=_blank>jillzhang</A>&nbsp;<A class=sendMsg2This title=给此人发送站内短消息 
href="http://space.cnblogs.com/msg/send/jillzhang">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</A> 
</DIV>
<DIV class=feedbackCon><SPAN class=blog_comment_body 
id=comment_body_1056141>多线程在UI和进程间通讯上都有广泛的应用</SPAN><BR></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle>
<DIV class=feedbackManage>&nbsp;&nbsp;<A 
onclick='ReplyComment("hsutao",1056376,"")' 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#commentform">回复</A>&nbsp;&nbsp;<A 
onclick='QuoteComment(1056376,"")' 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#commentform">引用</A>&nbsp;&nbsp;<A 
id=Comments1_CommentList_ctl04_DeleteLink 
href="javascript:__doPostBack('Comments1$CommentList$ctl04$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=Comments1_CommentList_ctl04_EditLink CausesValidation="False"></A> </DIV><A 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#1056376">#5楼</A><A 
id=comment_anchor_1056376 name=1056376></A>2008-01-28 16:20 | <A 
id=Comments1_CommentList_ctl04_NameLink target=_blank>hsutao[未注册用户]</A> </DIV>
<DIV class=feedbackCon><SPAN class=blog_comment_body 
id=comment_body_1056376>感谢分享.</SPAN><BR></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle>
<DIV class=feedbackManage>&nbsp;&nbsp;<A 
onclick='ReplyComment("C.C",1057866,"0yrVW2nVGvTYgjIYZDDP+2OfDJZMSrFyv6T1oqmzc2OC+X2fdMVujg==")' 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#commentform">回复</A>&nbsp;&nbsp;<A 
onclick='QuoteComment(1057866,"0yrVW2nVGvTYgjIYZDDP+2OfDJZMSrFyv6T1oqmzc2OC+X2fdMVujg==")' 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#commentform">引用</A>&nbsp;&nbsp;<A 
title=查看该作者发表过的评论 href="http://www.cnblogs.com/CommentsByAuthor.aspx?author=C.C" 
target=_blank>查看</A>&nbsp;&nbsp;<A id=Comments1_CommentList_ctl05_DeleteLink 
href="javascript:__doPostBack('Comments1$CommentList$ctl05$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=Comments1_CommentList_ctl05_EditLink CausesValidation="False"></A> </DIV><A 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#1057866">#6楼</A><A 
id=comment_anchor_1057866 name=1057866></A>2008-01-29 18:02 | <A 
id=Comments1_CommentList_ctl05_NameLink 
href="http://www.cnblogs.com/chenchaospr/" target=_blank>C.C</A>&nbsp;<A 
class=sendMsg2This title=给此人发送站内短消息 
href="http://space.cnblogs.com/msg/send/C.C">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</A> 
</DIV>
<DIV class=feedbackCon><SPAN class=blog_comment_body 
id=comment_body_1057866>一直关注你的文章,最近我也在学习wpf方面的东西,主要是3D交互展示部分,看楼主在wpf方面的造诣颇深,还望不吝解答小弟一个问题,先谢谢了！ 
<BR>我在创建了一个3D场景和动画以后，在geometryModel3d的material里进行了如下设置： <BR>DiffuseMaterial 
<BR>DiffuseMaterial.Brush <BR>VisualBrush <BR>VisualBrush.Visual <BR>Frame 
<BR>Source="..\Frames\TextAnimationExample.xaml" <BR>Width="400" Height="400" 
<BR>NavigationUIVisibility="Hidden" <BR>/VisualBrush.Visual <BR>/VisualBrush 
<BR>/DiffuseMaterial.Brush <BR>/DiffuseMaterial 
<BR>目的是想material表面呈现xaml资源文件中的3D动画,有点嵌套的感觉,可试验结果就是静止的一帧...很是不解... <BR>看 
在WPF中显示动态GIF 这篇文章说需要GifBitmapDecoder来配合gif 
格式播放，那我这样的需求该如何做呢？？希望周大侠不吝赐教，小弟深表感谢！</SPAN><BR></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle>
<DIV class=feedbackManage>&nbsp;&nbsp;<A 
onclick='ReplyComment("fox23",1065014,"6I8dlG6Jm3/Zw9+00XTHERr0+auRxvhtAghjQvQfgxhtMbJqi920lw==")' 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#commentform">回复</A>&nbsp;&nbsp;<A 
onclick='QuoteComment(1065014,"6I8dlG6Jm3/Zw9+00XTHERr0+auRxvhtAghjQvQfgxhtMbJqi920lw==")' 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#commentform">引用</A>&nbsp;&nbsp;<A 
title=查看该作者发表过的评论 
href="http://www.cnblogs.com/CommentsByAuthor.aspx?author=fox23" 
target=_blank>查看</A>&nbsp;&nbsp;<A id=Comments1_CommentList_ctl06_DeleteLink 
href="javascript:__doPostBack('Comments1$CommentList$ctl06$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=Comments1_CommentList_ctl06_EditLink CausesValidation="False"></A> </DIV><A 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#1065014">#7楼</A><A 
id=comment_anchor_1065014 name=1065014></A>2008-02-05 17:05 | <A 
id=Comments1_CommentList_ctl06_NameLink href="http://www.cnblogs.com/fox23/" 
target=_blank>fox23</A>&nbsp;<A class=sendMsg2This title=给此人发送站内短消息 
href="http://space.cnblogs.com/msg/send/fox23">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</A> 
</DIV>
<DIV class=feedbackCon><SPAN class=blog_comment_body 
id=comment_body_1065014>不错，收藏了</SPAN><BR></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle>
<DIV class=feedbackManage>&nbsp;&nbsp;<A 
onclick='ReplyComment("Peach",1280992,"Z7jIR6g7PV+LsPbLd8jPt9fDJ1wFbw+JoS016fHI+wC3YGMXAmYonQ==")' 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#commentform">回复</A>&nbsp;&nbsp;<A 
onclick='QuoteComment(1280992,"Z7jIR6g7PV+LsPbLd8jPt9fDJ1wFbw+JoS016fHI+wC3YGMXAmYonQ==")' 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#commentform">引用</A>&nbsp;&nbsp;<A 
title=查看该作者发表过的评论 
href="http://www.cnblogs.com/CommentsByAuthor.aspx?author=Peach" 
target=_blank>查看</A>&nbsp;&nbsp;<A id=Comments1_CommentList_ctl07_DeleteLink 
href="javascript:__doPostBack('Comments1$CommentList$ctl07$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=Comments1_CommentList_ctl07_EditLink CausesValidation="False"></A> </DIV><A 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#1280992">#8楼</A><A 
id=comment_anchor_1280992 name=1280992></A>2008-08-07 18:55 | <A 
id=Comments1_CommentList_ctl07_NameLink href="http://www.cnblogs.com/peach/" 
target=_blank>Peach</A>&nbsp;<A class=sendMsg2This title=给此人发送站内短消息 
href="http://space.cnblogs.com/msg/send/Peach">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</A> 
</DIV>
<DIV class=feedbackCon><SPAN class=blog_comment_body 
id=comment_body_1280992>感谢~<BR>刚好碰到这个问题，很典型的：<BR>一个上传下载控件，带进度条，多线程上传下载，进度条进度的实现就很好的用到这个知识。<BR>再次感谢</SPAN><BR></DIV></DIV>
<DIV class=feedbackItem>
<DIV class=feedbackListSubtitle>
<DIV class=feedbackManage>&nbsp;&nbsp;<A 
onclick='ReplyComment("CS2",1617320,"")' 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#commentform">回复</A>&nbsp;&nbsp;<A 
onclick='QuoteComment(1617320,"")' 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#commentform">引用</A>&nbsp;&nbsp;<A 
id=Comments1_CommentList_ctl08_DeleteLink 
href="javascript:__doPostBack('Comments1$CommentList$ctl08$DeleteLink','')"></A>&nbsp;&nbsp;<A 
id=Comments1_CommentList_ctl08_EditLink CausesValidation="False"></A> </DIV><A 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#1617320">#9楼</A><A 
id=comment_anchor_1617320 name=1617320></A><A name=Post></A>2009-08-17 18:29 | 
<A id=Comments1_CommentList_ctl08_NameLink target=_blank>CS2[未注册用户]</A> </DIV>
<DIV class=feedbackCon><SPAN class=blog_comment_body 
id=comment_body_1617320>好好的学习了一下<BR>非常清晰的技术文章，解决我的最近棘手的问题。</SPAN><BR></DIV></DIV>
<SCRIPT type=text/javascript>
    var commentAuthorHasChecked = false;
    var commentAuthorIsValid = false;
    var commentUrlIsValid = true;
    var commentEmailIsValid = true;
    var authenCodeHasChecked = false;
    var authenCodeIsValid = true;
    var hasLogined = false;
    
    function PostComment() {    
        
        var isValid = true;
        
        if($("#wrapAuthenCode").css("display")=="none"){
            ShowAuthenCode();
            $("#tip_AuthenCode").css("color","red");
            $("#tip_AuthenCode").html("请输入验证码！");
            isValid = false;
        }
        
        if(!hasLogined && !commentAuthorHasChecked){
            CheckAuthor();        
        }                
        if(!hasLogined && !commentAuthorIsValid){
            isValid = false;
        }
                       
        if(!authenCodeHasChecked){
            CheckAuthenCode();            
        }
        if(!authenCodeIsValid){
            isValid = false;
        }
        
        if(!hasLogined && !commentUrlIsValid){            
            isValid = false;
        }        
        if(!commentEmailIsValid){            
            isValid = false;
        }        
        if(!CheckCommentContent()){
            isValid = false;
        }    
        if(!isValid){
            return;
        }

        var content = $("#tbCommentBody").val();
        if(content.length>2000){
            alert("评论内容过长！不允许发布！");
            return;
        }        
        
       if ($("#span_comment_posted").html()!='' && $("#span_comment_posted").html()==content){
            alert("该评论已发表过!");
            return;
        }
        
        $("#tip_comment").html("评论提交中...");
        $("#span_comment_posted").html(content);
        //content = content.replace("'", "\\'");
        var email = $("#tbCommentEmail").val();
        var authenNum = $("#tbAuthenCode").val();
        var authenId = $("#span_comment_test").html();
        var comment = {};
        comment.authenNum = authenNum;
        comment.authenId= authenId;
        comment.parentId = 1055261;
        comment.blogId = 18579;
        comment.sourceUrl = 'http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html';
        comment.author = $("#tbCommentAuthor").val();
        comment.url = $("#tbCommentAuthorUrl").val();
        comment.authenCode = $("#tbAuthenCode").val();
        comment.email = email;
        comment.title = 'WPF的线程模型';
        comment.content = content;
        comment.parentCommentId = $("#span_parentcomment_id").html();
        $.ajax({
            url: '/ws/CommentService.asmx/AddAnonymousComment',
            data: $.toJSON(comment),
            type: "post",
            dataType: "json",
            contentType: "application/json; charset=utf8",
            success: function(data) {
               if (data.d["IsSuccess"]) {
                    ShowCommentMsg("感谢您的回复:)");
                    //RereshComments2(comment.parentId);
                    $("#tbCommentBody").val('');
                    //$("#divCommentShow").html(data.d["ReturnData"]+content.replace(/\n/g,"<br/>")+"<br/><br/>");
                    $("#divCommentShow").html($("#divCommentShow").html()+data.d["ReturnData"]); 
                    $("#tip_AuthenCode").html('');
                    RefreshAuthenCode();
                    $("#tbAuthenCode").val("");                    
                    CommentNotify(data.d["CommentID"]);
                }
                else {
                    ShowCommentMsg(data.d["ReturnData"]);//"抱歉！评论提交失败！请与管理员联系。");
                    $("#span_comment_posted").html(''); 
                }
            },
            error: function(xhr) {
                ShowCommentMsg("抱歉！评论提交失败！请与管理员联系。");
                $("#span_comment_posted").html('');  
                //alert(xhr.responseText);
            }
        }
        );
    }
    
    function RefreshAuthenCode(){
        AjaxPost("/ws/CommentService.asmx/RefreshAuthenCode","{}",RefreshImg); 
        $("#lnkRereshAuthenCode").html("<span style='color:red'>刷新中...</span>");
        return false;
    }
    
    function RefreshImg(response){
       $("#imgAuthenCode").attr("src","/Modules/CaptchaImage/ValidCodeImage.aspx?id="+encodeURIComponent(response));
       $("#span_comment_test").html(response);
       $("#lnkRereshAuthenCode").html("看不清，换一个");
    }
    
    function ShowAuthenCode(){
        //if($("#wrapAuthenCode").css("display")=="none"){    
        //    AjaxPost("/ws/CommentService.asmx/RefreshAuthenCode","{}",ShowAuthenCodeOk);
        //}
        $("#wrapAuthenCode").show();      
    }
    
    function ShowAuthenCodeOk(response){
         UpdateAuthenCode();
         $("#tbAuthenCode").val("");
         $("#wrapAuthenCode").show();
         $("#tip_AuthenCode").html('');
    }  
 
    
    function CheckAuthor(isOnblur){
        commentAuthorHasChecked = true;
        var maxLength = 30;
        if($("#tbCommentAuthor").val().length == 0){
            $("#tip_author").html("请输入您的昵称！");
            commentAuthorIsValid = false;
            return false;
        }     
        else if($("#tbCommentAuthor").val().length > maxLength){
            $("#tip_author").html("昵称不允许超过" + maxLength + "个字符！");
            commentAuthorIsValid = false;
            return false;
        }
        else{
            //if(isOnblur){
                AjaxPost("/ws/CommentService.asmx/IsAuthorExist","{author:'"+$("#tbCommentAuthor").val()+"'}" ,OnCheckAuthorExist);
            //}
            //else{
            //    $("#tip_author").html("");
            //    commentAuthorIsValid = true;
            //}
            return true;
        }
   }
   
    function OnCheckAuthorExist(response){        
        if(!response){
            $("#tip_author").html("");
            commentAuthorIsValid = true;
        }
        else{
            $("#tip_author").html("该昵称已被使用，请更换昵称");
            commentAuthorIsValid = false;
        }
   }
   
    function CheckUrl(){
        var maxLength = 50;
        var url = $("#tbCommentAuthorUrl").val();
        
        if(url.length == 0){
            commentUrlIsValid = true;
            return true;
        }
        else if(url.length > maxLength){
            $("#tip_url").html("主页地址不允许超过" + maxLength + "个字符！");
            commentUrlIsValid = false;
            return false;
        }
        else if(url.indexOf("http://")!=0 || url.indexOf(".") < 0){
            $("#tip_url").html("主页地址要以“http://”开头");
            commentUrlIsValid = false;
            return false;
        }
        else{
            $("#tip_url").html("");
            commentUrlIsValid = true;
            return true;
        }
   }
   
   function CheckEmail(){
        var email = $("#tbCommentEmail").val();
        if(email.length>0){
            var regExp = new RegExp("\\w+@((\\w|\-)+\\.)+[a-z]{2,3}");
            if(!regExp.test(email)){
                $("#tip_email").html("请输入正确的邮件地址!");
                commentEmailIsValid = false;
            }
            else{
                commentEmailIsValid = true;
                 $("#tip_email").html("");
            }
        }
        else{
            commentEmailIsValid = true;
            $("#tip_email").html("");  
        }
   }
   
   function CheckAuthenCode(){
        authenCodeHasChecked = true;
        var num = $("#tbAuthenCode").val();
        var id = $("#span_comment_test").html();
        $("#tip_AuthenCode").css("color","red");
        if(num.length==0){
             authenCodeIsValid = false;
             $("#tip_AuthenCode").html("请输入验证码！");
             return;
        }
        else if(num.length!=4){
            authenCodeIsValid = false;
            $("#tip_AuthenCode").html("请输入四位数字！");
             return;
        }
        else if(new RegExp("(\d+)").test(num)){
            authenCodeIsValid = false;
            $("#tip_AuthenCode").html("请输入四位数字！");
             return;
        }
        else{
            AjaxPost("/ws/CommentService.asmx/CheckAuthenCode","{number:"+num+",id:'"+id+"'}", OnCheckAuthenCode);
        }
   }
   
   function OnCheckAuthenCode(response){
        if(response){
            $("#tip_AuthenCode").css("color","green");
            $("#tip_AuthenCode").html("验证码输入正确！");
            authenCodeIsValid = true;            
        }
        else{
            $("#tip_AuthenCode").css("color","red");
            $("#tip_AuthenCode").html("验证码输错啦！");
            RefreshAuthenCode();
            authenCodeIsValid = false;           
        }
   }
   
   function CheckCommentContent(){
    if($("#tbCommentBody").val().length==0){
        alert("请输入评论内容！");
        return false;
    }
    return true;
   }
    
</SCRIPT>

<DIV class=commentform id=ctl05_comment_form><BR>
<SCRIPT type=text/javascript>
    try {
        if (!blog_ad_has_shown) {
            GA_googleFillSlot("cnblogs_commentbox_up");
        }
    }
    catch (e) { }
</SCRIPT>
<BR><BR>
<DIV id=ctl05_divCommentPannel>
<DIV id=divCommentShow></DIV>
<DIV id=comment_nav style="TEXT-ALIGN: right"><SPAN 
id=span_refresh_tips></SPAN><A id=lnk_RefreshComments 
onclick="return RefreshCommentList(1055261);" 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html###" 
name=commentform>刷新评论列表</A>&nbsp; <A onclick="return RefreshPage();" 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html###">刷新页面</A>&nbsp; 
<A 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html#top">返回页首</A></DIV>
<DIV id=commentform_title>发表评论 <SPAN class=ad_commentbox_up><A 
href="http://job.cnblogs.com/zt/200912YesHJ/" 
target=_blank>沪江网技术部招聘程序员</A></SPAN></DIV><SPAN id=tip_comment 
style="COLOR: red"></SPAN>
<P>昵称：<INPUT class=author id=tbCommentAuthor onblur=CheckAuthor() 
onfocus=ShowAuthenCode()> <SPAN id=tip_author style="COLOR: red"></SPAN><A 
href="http://passport.cnblogs.com/login.aspx?ReturnUrl=http%3a%2f%2fwww.cnblogs.com%2fzhouyinhui%2farchive%2f2008%2f01%2f27%2f1055261.html%3flogin%3d1%23commentform">[登录]</A> 
<A 
href="http://passport.cnblogs.com/register.aspx?ReturnUrl=http%3a%2f%2fwww.cnblogs.com%2fzhouyinhui%2farchive%2f2008%2f01%2f27%2f1055261.html%23Top">[注册]</A> 
</P>
<P>主页：<INPUT class=url id=tbCommentAuthorUrl onblur=CheckUrl() 
onfocus=ShowAuthenCode()> <SPAN id=tip_url style="COLOR: red"></SPAN></P>
<P>邮箱：<INPUT class=email id=tbCommentEmail onblur=CheckEmail() 
onfocus=ShowAuthenCode()>(仅博主可见) <SPAN id=tip_email 
style="COLOR: red"></SPAN></P>
<P id=wrapAuthenCode style="DISPLAY: none">验证码：<INPUT id=tbAuthenCode 
onblur=CheckAuthenCode()> <SPAN id=tip_AuthenCode></SPAN><IMG id=imgAuthenCode 
alt=验证码 src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ValidCodeImage.jpg" 
align=absMiddle> <A id=lnkRereshAuthenCode onclick="return RefreshAuthenCode();" 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html###">看不清，换一个</A> 
</P>
<P>评论内容：<SPAN id=tip_comment_content style="COLOR: red"></SPAN> <BR><TEXTAREA class=comment_textarea id=tbCommentBody onkeydown="return clt_enter(event)" onfocus=ShowAuthenCode()></TEXTAREA> 
<!--
<br /><input id="cbRememberMe" type="checkbox" />记住我的昵称和主页
--></P>
<P><INPUT class=comment_btn id=btn_comment_submit onclick="PostComment();return false;" type=button value=提交> 
&nbsp;&nbsp;<A 
href="http://passport.cnblogs.com/login.aspx?ReturnUrl=http%3a%2f%2fwww.cnblogs.com%2fzhouyinhui%2farchive%2f2008%2f01%2f27%2f1055261.html%3flogin%3d1%23commentform">登录</A>&nbsp;&nbsp;<A 
href="http://passport.cnblogs.com/register.aspx?ReturnUrl=http%3a%2f%2fwww.cnblogs.com%2fzhouyinhui%2farchive%2f2008%2f01%2f27%2f1055261.html%23Bottom">注册</A> 
</P>
<P>[使用Ctrl+Enter键快速提交评论] </P>
<DIV style="DISPLAY: none"><SPAN id=comment_edit_id></SPAN><SPAN 
id=span_parentcomment_id>0</SPAN> <SPAN id=span_parent_id>1055261</SPAN> <SPAN 
id=span_comment_replyto></SPAN><SPAN id=span_comment_posted></SPAN><SPAN 
id=span_comment_test>dw9Y+VfcjRM=</SPAN> </DIV></DIV>网站导航：<A 
href="http://www.cnblogs.com/" target=_blank>博客园首页</A> | <A 
href="http://home.cnblogs.com/" target=_blank>个人主页</A> | <A 
href="http://home.cnblogs.com/ing/" target=_blank>闪存</A> | <A 
href="http://news.cnblogs.com/" target=_blank>IT新闻</A> | <A 
href="http://job.cnblogs.com/" target=_blank>程序员招聘</A> | <A 
href="http://space.cnblogs.com/" target=_blank>社区</A> | <A 
href="http://space.cnblogs.com/q/" target=_blank>博问</A> | <A 
href="http://wz.cnblogs.com/" target=_blank>网摘</A><BR><BR>
<SCRIPT type=text/javascript>
    try {
        GA_googleFillSlot("cnblogs_blogpost_bottom");
    }
    catch (e) { }
</SCRIPT>
<BR>
<DIV class=itnews id=itnews>IT新闻:<BR>· <A 
href="http://news.cnblogs.com/n/53421/" 
target=_blank>苹果CEO乔布斯遭MAC用户PS恶搞</A><BR>· <A 
href="http://news.cnblogs.com/n/53420/" 
target=_blank>移动联通电信定制三款MOTO智系列Android手机</A><BR>· <A 
href="http://news.cnblogs.com/n/53419/" target=_blank>Google手机Nexus One试用 
不支持多点触摸？</A><BR>· <A href="http://news.cnblogs.com/n/53418/" 
target=_blank>中国研制出世界最快反病毒虚拟机</A><BR>· <A 
href="http://news.cnblogs.com/n/53417/" target=_blank>英报炮轰：Google英国收入25亿美元 
没交半点税</A><BR></DIV>
<DIV id=div_ad2><A href="http://www.china-pub.com/itbook/" 
target=_blank>China-pub 计算机图书网上专卖店！6.5万品种2-8折！</A><BR><A 
href="http://www.china-pub.com/static07/0901/zh_jueba_090121.asp" 
target=_blank>China-Pub 计算机绝版图书按需印刷服务</A><BR></DIV><BR>
<DIV id=HistoryToday><B>历史上的今天:</B><BR>2007-01-27 <A 
href="http://www.cnblogs.com/zhouyinhui/archive/2007/01/27/632010.html">获奖啦, 
微软亚洲研究院第九届学生实践项目</A><BR></DIV>
<DIV id=div_commentbox_nav>链接：<A 
href="http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html?switchskin=1#skinlist">切换模板</A><BR></DIV>
<DIV id=relative_search><BR><B>相关搜索:</B><BR><A 
href="http://zzk.cnblogs.com/s?w=WPF" target=_blank>WPF</A> </DIV>
<DIV id=relative_search><BR><B>在知识库中查看：</B><BR><A 
href="http://kb.cnblogs.com/a/1055261/">WPF的线程模型</A></DIV><BR></DIV></DIV><!--end: forFlow --></DIV><!--end: mainContent 主体内容容器-->
<DIV id=sideBar>
<DIV id=sideBarMain><!--done-->
<DIV class=newsItem>
<H3 class=catListTitle>公告</H3>
<P><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/MVP_Small3.jpg" 
border=0></A><BR></P>
<P>&nbsp;<A href="http://www.ge.com/" target=_blank><IMG alt="" 
src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/gelogo.png" 
align=center></A></P>
<P>&nbsp;<A href="http://www.ge.com/"><STRONG>GE:Imagination at 
work</STRONG></A></P>
<P>&nbsp;</P>
<DIV id=profile_block><A href="http://home.cnblogs.com/zhouyinhui/" 
target=_blank>我的主页</A>&nbsp; <A 
href="http://home.cnblogs.com/zhouyinhui/detail/" target=_blank>个人资料</A><BR><A 
href="http://home.cnblogs.com/zhouyinhui/ing/" target=_blank>我的闪存</A>&nbsp; <A 
href="http://space.cnblogs.com/msg/send/å¨é¶è¾" 
target=_blank>发短消息</A></DIV></DIV>
<DIV id=calendar></DIV>
<DIV id=leftcontentcontainer>
<SCRIPT type=text/javascript>
var blogapp = 'zhouyinhui';
</SCRIPT>

<DIV class=mySearch>
<H3 class=catListTitle>搜索</H3>
<DIV class=div_my_zzk><INPUT class=input_my_zzk id=q 
onkeydown="return zzk_go_enter(event);">&nbsp;<INPUT class=btn_my_zzk id=btnZzk onclick=zzk_go() type=button value=找找看></DIV>
<DIV class=div_my_zzk><INPUT class=input_my_zzk id=google_q 
onkeydown="return google_go_enter(event)" name=google_q>&nbsp;<INPUT class=btn_my_zzk onclick=google_go() type=button value=Google搜索></DIV></DIV>
<DIV class=catListPostCategory>
<H3 class=catListTitle>随笔分类<SPAN 
style="FONT-WEIGHT: normal; FONT-SIZE: 11px">(247)</SPAN></H3>
<UL>
  <LI><A id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl01_Link 
  href="http://www.cnblogs.com/zhouyinhui/category/78918.html">.Net(52)</A> <A 
  id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl01_RssLink 
  title="Subscribe to .Net(52)" 
  href="http://www.cnblogs.com/zhouyinhui/category/78918.html/rss">(rss)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl02_Link 
  href="http://www.cnblogs.com/zhouyinhui/category/208319.html">Algorithm(20)</A> 
  <A id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl02_RssLink 
  title="Subscribe to Algorithm(20)" 
  href="http://www.cnblogs.com/zhouyinhui/category/208319.html/rss">(rss)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl03_Link 
  href="http://www.cnblogs.com/zhouyinhui/category/143606.html">Composite 
  Application(12)</A> <A 
  id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl03_RssLink 
  title="Subscribe to Composite Application(12)" 
  href="http://www.cnblogs.com/zhouyinhui/category/143606.html/rss">(rss)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl04_Link 
  href="http://www.cnblogs.com/zhouyinhui/category/81647.html">OO &amp; 
  Pattern(4)</A> <A 
  id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl04_RssLink 
  title="Subscribe to OO &amp; Pattern(4)" 
  href="http://www.cnblogs.com/zhouyinhui/category/81647.html/rss">(rss)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl05_Link 
  href="http://www.cnblogs.com/zhouyinhui/category/78919.html">Other(36)</A> <A 
  id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl05_RssLink 
  title="Subscribe to Other(36)" 
  href="http://www.cnblogs.com/zhouyinhui/category/78919.html/rss">(rss)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl06_Link 
  href="http://www.cnblogs.com/zhouyinhui/category/130044.html">Silverlight(3)</A> 
  <A id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl06_RssLink 
  title="Subscribe to Silverlight(3)" 
  href="http://www.cnblogs.com/zhouyinhui/category/130044.html/rss">(rss)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl07_Link 
  href="http://www.cnblogs.com/zhouyinhui/category/128975.html">Team(5)</A> <A 
  id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl07_RssLink 
  title="Subscribe to Team(5)" 
  href="http://www.cnblogs.com/zhouyinhui/category/128975.html/rss">(rss)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl08_Link 
  href="http://www.cnblogs.com/zhouyinhui/category/176158.html">UML(3)</A> <A 
  id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl08_RssLink 
  title="Subscribe to UML(3)" 
  href="http://www.cnblogs.com/zhouyinhui/category/176158.html/rss">(rss)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl09_Link 
  href="http://www.cnblogs.com/zhouyinhui/category/86467.html">WPF(108)</A> <A 
  id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl09_RssLink 
  title="Subscribe to WPF(108)" 
  href="http://www.cnblogs.com/zhouyinhui/category/86467.html/rss">(rss)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl10_Link 
  href="http://www.cnblogs.com/zhouyinhui/category/78664.html">XNA(4)</A> <A 
  id=SingleColumn1_Categories_CatList_ctl00_LinkList_ctl10_RssLink 
  title="Subscribe to XNA(4)" 
  href="http://www.cnblogs.com/zhouyinhui/category/78664.html/rss">(rss)</A> 
  </LI></UL></DIV>
<DIV class=catListPostArchive>
<H3 class=catListTitle>随笔档案<SPAN 
style="FONT-WEIGHT: normal; FONT-SIZE: 11px">(227)</SPAN></H3>
<UL>
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl01_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2009/12.html">2009年12月 (5)</A> 

  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl02_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2009/11.html">2009年11月 (5)</A> 

  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl03_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2009/10.html">2009年10月 (7)</A> 

  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl04_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2009/09.html">2009年9月 (9)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl05_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2009/08.html">2009年8月 (3)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl06_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2009/07.html">2009年7月 (3)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl07_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2009/06.html">2009年6月 (6)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl08_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2009/02.html">2009年2月 (4)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl09_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2009/01.html">2009年1月 (3)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl10_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2008/12.html">2008年12月 (4)</A> 

  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl11_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2008/11.html">2008年11月 (3)</A> 

  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl12_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2008/10.html">2008年10月 (1)</A> 

  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl13_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2008/09.html">2008年9月 (6)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl14_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2008/08.html">2008年8月 (6)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl15_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2008/07.html">2008年7月 (6)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl16_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2008/06.html">2008年6月 (2)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl17_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2008/05.html">2008年5月 (4)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl18_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2008/04.html">2008年4月 (5)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl19_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2008/03.html">2008年3月 (4)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl20_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2008/02.html">2008年2月 (1)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl21_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2008/01.html">2008年1月 (8)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl22_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2007/12.html">2007年12月 (7)</A> 

  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl23_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2007/11.html">2007年11月 (6)</A> 

  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl24_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2007/10.html">2007年10月 (5)</A> 

  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl25_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2007/09.html">2007年9月 (5)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl26_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2007/08.html">2007年8月 (11)</A> 

  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl27_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2007/07.html">2007年7月 (8)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl28_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2007/06.html">2007年6月 (5)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl29_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2007/05.html">2007年5月 (11)</A> 

  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl30_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2007/04.html">2007年4月 (5)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl31_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2007/03.html">2007年3月 (17)</A> 

  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl32_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2007/02.html">2007年2月 (1)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl33_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2007/01.html">2007年1月 (6)</A> 
  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl34_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2006/12.html">2006年12月 (8)</A> 

  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl35_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2006/11.html">2006年11月 (2)</A> 

  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl36_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2006/10.html">2006年10月 (7)</A> 

  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl37_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2006/06.html">2006年6月 (11)</A> 

  <LI><A id=SingleColumn1_Categories_CatList_ctl01_LinkList_ctl38_Link 
  href="http://www.cnblogs.com/zhouyinhui/archive/2006/05.html">2006年5月 (17)</A> 
  </LI></UL></DIV></DIV></DIV><!--end: sideBarMain --></DIV><!--end: sideBar 侧边栏容器 -->
<DIV class=clear></DIV></DIV><!--end: main -->
<DIV class=clear></DIV>
<DIV id=footer><!--done-->Copyright ©2009 周银辉 </DIV><!--end: footer --></DIV><!--end: home 自定义的最大容器 --></FORM>
<SCRIPT src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/shCore.js" 
type=text/javascript></SCRIPT>

<SCRIPT src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/shLanguage.js" 
type=text/javascript></SCRIPT>

<SCRIPT type=text/javascript>
        try {
            SyntaxHighlighter.config.clipboardSwf = 'http://common.cnblogs.com/flash/clipboard.swf'
            SyntaxHighlighter.all();
        } catch (e) { }
    </SCRIPT>

<SCRIPT src="WPF的线程模型 - this_Study(DateTime_Now) - 博客园.files/ShowHidden.js" 
type=text/javascript></SCRIPT>

<SCRIPT type=text/javascript>
        var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
        document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </SCRIPT>

<SCRIPT type=text/javascript>
        try {
            var pageTracker = _gat._getTracker("UA-476124-1");
            pageTracker._trackPageview();
        } catch (err) { }</SCRIPT>
</BODY></HTML>
